package com.roads.supervisor.service.impl;

import com.roads.common.constant.Constants;
import com.roads.common.core.domain.entity.SysUser;
import com.roads.common.core.text.Convert;
import com.roads.common.utils.SecurityUtils;
import com.roads.common.utils.uuid.IdUtils;
import com.roads.project.domain.ProSupervisorItems;
import com.roads.project.mapper.ProSupervisorItemsMapper;
import com.roads.supervisor.domain.SupBoq;
import com.roads.supervisor.domain.SupMeterageDetailConstruction;
import com.roads.supervisor.domain.SupMeterageDetailDefect;
import com.roads.supervisor.domain.SupMeterageDetailOther;
import com.roads.supervisor.domain.SupMeterageDetailWinter;
import com.roads.supervisor.domain.SupMeterageMaster;
import com.roads.supervisor.mapper.SupBoqMapper;
import com.roads.supervisor.mapper.SupMeterageDetailConstructionMapper;
import com.roads.supervisor.mapper.SupMeterageDetailDefectMapper;
import com.roads.supervisor.mapper.SupMeterageDetailOtherMapper;
import com.roads.supervisor.mapper.SupMeterageDetailWinterMapper;
import com.roads.supervisor.mapper.SupMeterageMasterMapper;
import com.roads.supervisor.service.ISupMeterageDetailService;
import com.roads.system.mapper.SysUserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName EngMeterageDetailServiceImpl
 * @Description 监理计量细表Service业务层处理
 * @Author nhp
 * @Date 2022/3/1 0001 17:27
 * @Version 1.0.0
 **/
@Service
public class SupMeterageDetailServiceImpl implements ISupMeterageDetailService {

    @Autowired
    private SupMeterageMasterMapper masterMapper;

    @Autowired
    private SupMeterageDetailConstructionMapper detailConstructionMapper;

    @Autowired
    private SupMeterageDetailWinterMapper detailWinterMapper;

    @Autowired
    private SupMeterageDetailDefectMapper detailDefectMapper;

    @Autowired
    private SupMeterageDetailOtherMapper detailOtherMapper;

    @Autowired
    private SupBoqMapper boqMapper;

    @Autowired
    private SysUserMapper userMapper;

    @Autowired
    private ProSupervisorItemsMapper proSupervisorItemsMapper;

    /**
     * 查询监理计量施工期列表
     *
     * @param model 施工期
     * @return 施工期集合
     */
    @Override
    public List<SupMeterageDetailConstruction> selectConstructionList(SupMeterageDetailConstruction model) {
        return detailConstructionMapper.selectModelList(model);
    }

    /**
     * 清单是否计量
     *
     * @param supBoq 清单
     * @return 结果
     */
    @Override
    public boolean hasMeterage(SupBoq supBoq) {
        int count = 0;
        if (Constants.SUPERVISION_BOQ_TYPE_CONSTRUCTION.equals(supBoq.getBoqType())) {
            // 施工期
            count = detailConstructionMapper.hasMeterage(supBoq.getInstitutionBoqCode());
        } else if (Constants.SUPERVISION_BOQ_TYPE_WINTER.equals(supBoq.getBoqType())) {
            // 冬休期
            count = detailWinterMapper.hasMeterage(supBoq.getInstitutionBoqCode());
        } else {
            // 缺陷责任期
            count = detailDefectMapper.hasMeterage(supBoq.getInstitutionBoqCode());
        }
        return count > 0;
    }

    /**
     * 监理计量-施工期批量新增
     *
     * @param masterId 监理计量主表ID
     * @param ids 施工期清单id集合
     * @return 结果
     */
    @Override
    public int saveDetailConstruction(Long masterId, String ids) {
        List<SupBoq> boqList = boqMapper.selectModelListByIds(Convert.toStrArray(ids));
        List<SupMeterageDetailConstruction> details = new ArrayList<>();
        // 当前登录用户
        SysUser loginUser = userMapper.selectUserById(SecurityUtils.getUserId());
        for (SupBoq boq : boqList) {
            SupMeterageDetailConstruction detail = new SupMeterageDetailConstruction();
            detail.setMasterId(masterId);
            detail.setInstitutionBoqCode(boq.getInstitutionBoqCode());
            detail.setBoqCode(boq.getBoqCode());
            detail.setBoqName(boq.getBoqName());
            detail.setAncestors(boq.getAncestors());
            detail.setOrderNum(boq.getOrderNum());
            detail.setUnit(boq.getUnit());
            detail.setContractDepreciationTotal(boq.getDepreciationTotal());
            detail.setContractPersonAmount(boq.getPersonAmount());
            detail.setContractPeriodAmount(boq.getPeriodAmount());
            detail.setContractPrice(boq.getPrice());
            detail.setContractTotal(boq.getTotal());
            detail.setIsEdit(Constants.NO);
            detail.setComplete(Constants.NO);
            detail.setDept(loginUser.getDeptId());
            detail.setDeptName(loginUser.getDept().getDeptName());
            detail.setUser(loginUser.getUserName());
            detail.setUserName(loginUser.getNickName());
            String uuid = IdUtils.simpleUuid();
            detail.setAnnexUuid(uuid);
            detail.setCreateBy(loginUser.getUserName());
            details.add(detail);
        }
        // 批量插入
        detailConstructionMapper.insertBatch(details);
        return 1;
    }

    /**
     * 根据ID获取施工期清单详情
     *
     * @param id 自增主键
     * @return 施工期清单详情
     */
    @Override
    public SupMeterageDetailConstruction getDetailConstructionById(Long id) {
        return detailConstructionMapper.getModelById(id);
    }

    /**
     * 修改监理计量-施工期详情
     *
     * @param model 修改数据
     * @return 结果
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public int updateDetailConstruction(SupMeterageDetailConstruction model) {
        // 施工期清单
        SupBoq supBoq = boqMapper.getModelByInstitutionBoqCode(model.getInstitutionBoqCode());
        // 取出修改前的数据
        SupMeterageDetailConstruction beforeUpdateDetail = detailConstructionMapper.getModelById(model.getId());
        // 修改前的值和修改值
        BigDecimal oldPeriodAmount = beforeUpdateDetail.getPeriodAmount() == null ? new BigDecimal(0) : beforeUpdateDetail.getPeriodAmount();
        BigDecimal newPeriodAmount = model.getPeriodAmount() == null ? new BigDecimal(0) : model.getPeriodAmount();
        // 修改前的值和修改值发生改变，需要重置清单里的已计量数量和剩余数量
        if (oldPeriodAmount.compareTo(newPeriodAmount) != 0) {
            // 已计量数量和剩余数量
            BigDecimal alreadyAmount = supBoq.getAlreadyAmount() == null ? new BigDecimal(0) : supBoq.getAlreadyAmount();
            BigDecimal remainderAmount = supBoq.getRemainderAmount() == null ? new BigDecimal(0) : supBoq.getRemainderAmount();
            alreadyAmount = alreadyAmount.subtract(oldPeriodAmount).add(newPeriodAmount);
            remainderAmount = remainderAmount.add(oldPeriodAmount).subtract(newPeriodAmount);
            supBoq.setAlreadyAmount(alreadyAmount);
            supBoq.setRemainderAmount(remainderAmount);
            // 如果剩余数量小于0，则该清单完成计量
            int result = supBoq.getRemainderAmount().compareTo(new BigDecimal(0));
            if ( result == -1 || result == 0) {
                supBoq.setComplete(Constants.YES);
                model.setComplete(Constants.YES);
            } else {
                supBoq.setComplete(Constants.NO);
                model.setComplete(Constants.NO);
            }
            // 更新合同清单的已计量数量和剩余数量
            boqMapper.update(supBoq);
            // 如果创建者不是自己，修改标识改成 true
            String loginUserName = SecurityUtils.getUsername();
            if (!loginUserName.equals(model.getCreateBy())) {
                model.setIsEdit(Constants.YES);
            }
        }
        return detailConstructionMapper.update(model);
    }

    /**
     * 删除监理计量-施工期详情
     *
     * @param ids 主键集合
     * @return 结果
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public int deleteDetailConstruction(Long[] ids) {
        for (int i = 0; i < ids.length; i++) {
            SupMeterageDetailConstruction detail = detailConstructionMapper.getModelById(ids[i]);
            BigDecimal periodAmount = detail.getPeriodAmount() == null ? new BigDecimal(0) : detail.getPeriodAmount();
            SupBoq supBoq = boqMapper.getModelByInstitutionBoqCode(detail.getInstitutionBoqCode());
            BigDecimal alreadyAmount = supBoq.getAlreadyAmount() == null ? new BigDecimal(0) : supBoq.getAlreadyAmount();
            BigDecimal remainderAmount = supBoq.getRemainderAmount() == null ? new BigDecimal(0) : supBoq.getRemainderAmount();
            supBoq.setAlreadyAmount(alreadyAmount.subtract(periodAmount));
            supBoq.setRemainderAmount(remainderAmount.add(periodAmount));
            // 设置工程量清单是否完成
            if (remainderAmount.compareTo(new BigDecimal(0)) == 1) {
                supBoq.setComplete(Constants.NO);
            } else {
                supBoq.setComplete(Constants.YES);
            }
            boqMapper.update(supBoq);
            detailConstructionMapper.delete(ids[i]);
        }
        return 1;
    }

    /**
     * 查询监理计量冬休期列表
     *
     * @param model 冬休期
     * @return 冬休期集合
     */
    @Override
    public List<SupMeterageDetailWinter> selectWinterList(SupMeterageDetailWinter model) {
        return detailWinterMapper.selectModelList(model);
    }

    /**
     * 监理计量-冬休期批量新增
     *
     * @param masterId 监理计量主表ID
     * @param ids 冬休期清单id集合
     * @return 结果
     */
    @Override
    public int saveDetailWinter(Long masterId, String ids) {
        List<SupBoq> boqList = boqMapper.selectModelListByIds(Convert.toStrArray(ids));
        List<SupMeterageDetailWinter> details = new ArrayList<>();
        // 当前登录用户
        SysUser loginUser = userMapper.selectUserById(SecurityUtils.getUserId());
        for (SupBoq boq : boqList) {
            SupMeterageDetailWinter detail = new SupMeterageDetailWinter();
            detail.setMasterId(masterId);
            detail.setInstitutionBoqCode(boq.getInstitutionBoqCode());
            detail.setBoqCode(boq.getBoqCode());
            detail.setBoqName(boq.getBoqName());
            detail.setAncestors(boq.getAncestors());
            detail.setOrderNum(boq.getOrderNum());
            detail.setUnit(boq.getUnit());
            detail.setContractDepreciationTotal(boq.getDepreciationTotal());
            detail.setContractPersonAmount(boq.getPersonAmount());
            detail.setContractPeriodAmount(boq.getPeriodAmount());
            detail.setContractPrice(boq.getPrice());
            detail.setContractTotal(boq.getTotal());
            detail.setIsEdit(Constants.NO);
            detail.setComplete(Constants.NO);
            detail.setDept(loginUser.getDeptId());
            detail.setDeptName(loginUser.getDept().getDeptName());
            detail.setUser(loginUser.getUserName());
            detail.setUserName(loginUser.getNickName());
            String uuid = IdUtils.simpleUuid();
            detail.setAnnexUuid(uuid);
            detail.setCreateBy(loginUser.getUserName());
            details.add(detail);
        }
        // 批量插入
        detailWinterMapper.insertBatch(details);
        return 1;
    }

    /**
     * 根据ID获取冬休期清单详情
     *
     * @param id 自增主键
     * @return 冬休期清单详情
     */
    @Override
    public SupMeterageDetailWinter getDetailWinterById(Long id) {
        return detailWinterMapper.getModelById(id);
    }

    /**
     * 修改监理计量-冬休期详情
     *
     * @param model 修改数据
     * @return 结果
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public int updateDetailWinter(SupMeterageDetailWinter model) {
        // 施工期清单
        SupBoq supBoq = boqMapper.getModelByInstitutionBoqCode(model.getInstitutionBoqCode());
        // 取出修改前的数据
        SupMeterageDetailWinter beforeUpdateDetail = detailWinterMapper.getModelById(model.getId());
        // 修改前的值和修改值
        BigDecimal oldPeriodAmount = beforeUpdateDetail.getPeriodAmount() == null ? new BigDecimal(0) : beforeUpdateDetail.getPeriodAmount();
        BigDecimal newPeriodAmount = model.getPeriodAmount() == null ? new BigDecimal(0) : model.getPeriodAmount();
        // 修改前的值和修改值发生改变，需要重置清单里的已计量数量和剩余数量
        if (oldPeriodAmount.compareTo(newPeriodAmount) != 0) {
            // 已计量数量和剩余数量
            BigDecimal alreadyAmount = supBoq.getAlreadyAmount() == null ? new BigDecimal(0) : supBoq.getAlreadyAmount();
            BigDecimal remainderAmount = supBoq.getRemainderAmount() == null ? new BigDecimal(0) : supBoq.getRemainderAmount();
            alreadyAmount = alreadyAmount.subtract(oldPeriodAmount).add(newPeriodAmount);
            remainderAmount = remainderAmount.add(oldPeriodAmount).subtract(newPeriodAmount);
            supBoq.setAlreadyAmount(alreadyAmount);
            supBoq.setRemainderAmount(remainderAmount);
            // 如果剩余数量小于0，则该清单完成计量
            int result = supBoq.getRemainderAmount().compareTo(new BigDecimal(0));
            if ( result == -1 || result == 0) {
                supBoq.setComplete(Constants.YES);
                model.setComplete(Constants.YES);
            } else {
                supBoq.setComplete(Constants.NO);
                model.setComplete(Constants.NO);
            }
            // 更新合同清单的已计量数量和剩余数量
            boqMapper.update(supBoq);
            // 如果创建者不是自己，修改标识改成 true
            String loginUserName = SecurityUtils.getUsername();
            if (!loginUserName.equals(model.getCreateBy())) {
                model.setIsEdit(Constants.YES);
            }
        }
        return detailWinterMapper.update(model);
    }

    /**
     * 删除监理计量-冬休期详情
     *
     * @param ids 主键集合
     * @return 结果
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public int deleteDetailWinter(Long[] ids) {
        for (int i = 0; i < ids.length; i++) {
            SupMeterageDetailWinter detail = detailWinterMapper.getModelById(ids[i]);
            BigDecimal periodAmount = detail.getPeriodAmount() == null ? new BigDecimal(0) : detail.getPeriodAmount();
            SupBoq supBoq = boqMapper.getModelByInstitutionBoqCode(detail.getInstitutionBoqCode());
            BigDecimal alreadyAmount = supBoq.getAlreadyAmount() == null ? new BigDecimal(0) : supBoq.getAlreadyAmount();
            BigDecimal remainderAmount = supBoq.getRemainderAmount() == null ? new BigDecimal(0) : supBoq.getRemainderAmount();
            supBoq.setAlreadyAmount(alreadyAmount.subtract(periodAmount));
            supBoq.setRemainderAmount(remainderAmount.add(periodAmount));
            // 设置工程量清单是否完成
            if (remainderAmount.compareTo(new BigDecimal(0)) == 1) {
                supBoq.setComplete(Constants.NO);
            } else {
                supBoq.setComplete(Constants.YES);
            }
            boqMapper.update(supBoq);
            detailWinterMapper.delete(ids[i]);
        }
        return 1;
    }

    /**
     * 查询监理计量缺陷责任期列表
     *
     * @param model 缺陷责任期
     * @return 缺陷责任期集合
     */
    @Override
    public List<SupMeterageDetailDefect> selectDefectList(SupMeterageDetailDefect model) {
        return detailDefectMapper.selectModelList(model);
    }

    /**
     * 监理计量-缺陷责任期批量新增
     *
     * @param masterId 监理计量主表ID
     * @param ids 缺陷责任期清单id集合
     * @return 结果
     */
    @Override
    public int saveDetailDefect(Long masterId, String ids) {
        List<SupBoq> boqList = boqMapper.selectModelListByIds(Convert.toStrArray(ids));
        List<SupMeterageDetailDefect> details = new ArrayList<>();
        // 当前登录用户
        SysUser loginUser = userMapper.selectUserById(SecurityUtils.getUserId());
        for (SupBoq boq : boqList) {
            SupMeterageDetailDefect detail = new SupMeterageDetailDefect();
            detail.setMasterId(masterId);
            detail.setInstitutionBoqCode(boq.getInstitutionBoqCode());
            detail.setBoqCode(boq.getBoqCode());
            detail.setBoqName(boq.getBoqName());
            detail.setAncestors(boq.getAncestors());
            detail.setOrderNum(boq.getOrderNum());
            detail.setUnit(boq.getUnit());
            detail.setContractDepreciationTotal(boq.getDepreciationTotal());
            detail.setContractPersonAmount(boq.getPersonAmount());
            detail.setContractPeriodAmount(boq.getPeriodAmount());
            detail.setContractPrice(boq.getPrice());
            detail.setContractTotal(boq.getTotal());
            detail.setIsEdit(Constants.NO);
            detail.setComplete(Constants.NO);
            detail.setDept(loginUser.getDeptId());
            detail.setDeptName(loginUser.getDept().getDeptName());
            detail.setUser(loginUser.getUserName());
            detail.setUserName(loginUser.getNickName());
            String uuid = IdUtils.simpleUuid();
            detail.setAnnexUuid(uuid);
            detail.setCreateBy(loginUser.getUserName());
            details.add(detail);
        }
        // 批量插入
        detailDefectMapper.insertBatch(details);
        return 1;
    }

    /**
     * 根据ID获取缺陷责任期清单详情
     *
     * @param id 自增主键
     * @return 缺陷责任期清单详情
     */
    @Override
    public SupMeterageDetailDefect getDetailDefectById(Long id) {
        return detailDefectMapper.getModelById(id);
    }

    /**
     * 修改监理计量-缺陷责任期详情
     *
     * @param model 修改数据
     * @return 结果
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public int updateDetailDefect(SupMeterageDetailDefect model) {
        // 施工期清单
        SupBoq supBoq = boqMapper.getModelByInstitutionBoqCode(model.getInstitutionBoqCode());
        // 取出修改前的数据
        SupMeterageDetailDefect beforeUpdateDetail = detailDefectMapper.getModelById(model.getId());
        // 修改前的值和修改值
        BigDecimal oldPeriodAmount = beforeUpdateDetail.getPeriodAmount() == null ? new BigDecimal(0) : beforeUpdateDetail.getPeriodAmount();
        BigDecimal newPeriodAmount = model.getPeriodAmount() == null ? new BigDecimal(0) : model.getPeriodAmount();
        // 修改前的值和修改值发生改变，需要重置清单里的已计量数量和剩余数量
        if (oldPeriodAmount.compareTo(newPeriodAmount) != 0) {
            // 已计量数量和剩余数量
            BigDecimal alreadyAmount = supBoq.getAlreadyAmount() == null ? new BigDecimal(0) : supBoq.getAlreadyAmount();
            BigDecimal remainderAmount = supBoq.getRemainderAmount() == null ? new BigDecimal(0) : supBoq.getRemainderAmount();
            alreadyAmount = alreadyAmount.subtract(oldPeriodAmount).add(newPeriodAmount);
            remainderAmount = remainderAmount.add(oldPeriodAmount).subtract(newPeriodAmount);
            supBoq.setAlreadyAmount(alreadyAmount);
            supBoq.setRemainderAmount(remainderAmount);
            // 如果剩余数量小于0，则该清单完成计量
            int result = supBoq.getRemainderAmount().compareTo(new BigDecimal(0));
            if ( result == -1 || result == 0) {
                supBoq.setComplete(Constants.YES);
                model.setComplete(Constants.YES);
            } else {
                supBoq.setComplete(Constants.NO);
                model.setComplete(Constants.NO);
            }
            // 更新合同清单的已计量数量和剩余数量
            boqMapper.update(supBoq);
            // 如果创建者不是自己，修改标识改成 true
            String loginUserName = SecurityUtils.getUsername();
            if (!loginUserName.equals(model.getCreateBy())) {
                model.setIsEdit(Constants.YES);
            }
        }
        return detailDefectMapper.update(model);
    }

    /**
     * 删除监理计量-缺陷责任期详情
     *
     * @param ids 主键集合
     * @return 结果
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public int deleteDetailDefect(Long[] ids) {
        for (int i = 0; i < ids.length; i++) {
            SupMeterageDetailDefect detail = detailDefectMapper.getModelById(ids[i]);
            BigDecimal periodAmount = detail.getPeriodAmount() == null ? new BigDecimal(0) : detail.getPeriodAmount();
            SupBoq supBoq = boqMapper.getModelByInstitutionBoqCode(detail.getInstitutionBoqCode());
            BigDecimal alreadyAmount = supBoq.getAlreadyAmount() == null ? new BigDecimal(0) : supBoq.getAlreadyAmount();
            BigDecimal remainderAmount = supBoq.getRemainderAmount() == null ? new BigDecimal(0) : supBoq.getRemainderAmount();
            supBoq.setAlreadyAmount(alreadyAmount.subtract(periodAmount));
            supBoq.setRemainderAmount(remainderAmount.add(periodAmount));
            // 设置工程量清单是否完成
            if (remainderAmount.compareTo(new BigDecimal(0)) == 1) {
                supBoq.setComplete(Constants.NO);
            } else {
                supBoq.setComplete(Constants.YES);
            }
            boqMapper.update(supBoq);
            detailDefectMapper.delete(ids[i]);
        }
        return 1;
    }

    /**
     * 查询监理计量其他支付项目列表
     *
     * @param model 其他支付项目
     * @return 施工期集合
     */
    @Override
    public List<SupMeterageDetailOther> selectOtherList(SupMeterageDetailOther model) {
        return detailOtherMapper.selectModelList(model);
    }

    /**
     * 根据ID获取其他支付项目详情
     *
     * @param id 自增主键
     * @return 其他支付项目详情
     */
    @Override
    public SupMeterageDetailOther getDetailOtherById(Long id) {
        return detailOtherMapper.getModelById(id);
    }

    /**
     * 修改监理计量-其他支付项目详情
     *
     * @param model 修改数据
     * @return 结果
     */
    @Override
    public int updateDetailOther(SupMeterageDetailOther model) {
        // 取出原有数据
        SupMeterageDetailOther old = detailOtherMapper.getModelById(model.getId());
        BigDecimal oldTotal = old.getTotal() == null ? new BigDecimal(0) : old.getTotal();
        BigDecimal newTotal = model.getTotal() == null ? new BigDecimal(0) : model.getTotal();
        // 值发生改变
        if (oldTotal.compareTo(newTotal) != 0) {
            // 如果创建者不是自己，修改标识改成 true
            String loginUserName = SecurityUtils.getUsername();
            if (!loginUserName.equals(model.getCreateBy())) {
                model.setIsEdit(Constants.YES);
            }
        }
        return detailOtherMapper.update(model);
    }

    /**
     * 同步其他支付项目固定值
     * @param masterId 主表主键
     * @return 结果
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public int syncDetailOtherItem(Long masterId) {
        SupMeterageMaster master = masterMapper.getModelById(masterId);
        // 先删除当前用户下的支付项目
        detailOtherMapper.deleteByUser(master.getMasterId(), master.getCurrentUser());
        SysUser currentWorkflowUser = userMapper.selectUserByUserName(master.getCurrentUser());
        List<SupMeterageDetailOther> others = createMeterageOtherList(master, currentWorkflowUser);
        detailOtherMapper.insertBatch(others);
        return 1;
    }

    /**
     * 创建监理计量-其他支付项目固定值集合
     *
     * @param master 主表信息
     * @param user 用户
     * @return 固定值支付项目集合
     */
    @Override
    public List<SupMeterageDetailOther> createMeterageOtherList(SupMeterageMaster master, SysUser user) {
        // 添加其他支付项目
        ProSupervisorItems search = new ProSupervisorItems();
        search.setProjectId(master.getProjectId());
        search.setComputeMode(Constants.FIXED_VALUE);
        search.setItemStatus(Constants.SUCCESS);
        List<ProSupervisorItems> paymentItems = proSupervisorItemsMapper.selectModelList(search);
        List<SupMeterageDetailOther> others = new ArrayList<>();
        for (ProSupervisorItems item : paymentItems) {
            SupMeterageDetailOther other = new SupMeterageDetailOther();
            other.setMasterId(master.getMasterId());
            other.setItemCode(item.getItemCode());
            other.setItemName(item.getItemName());
            other.setItemOrder(item.getItemOrder());
            other.setAnnexUuid(IdUtils.simpleUuid());
            other.setIsEdit(Constants.NO);
            other.setDept(user.getDeptId());
            other.setDeptName(user.getDept().getDeptName());
            other.setUser(user.getUserName());
            other.setUserName(user.getNickName());
            other.setCreateBy(user.getUserName());
            others.add(other);
        }
        return others;
    }
}
